<?php
$callback = htmlentities($_GET['callback']);
date_default_timezone_set("Asia/ShangHai");
$user = htmlentities($_GET['user']);
		$face_id = (int)$_GET['face_id'];
		include("config.php");
		$Connect = new PDO('mysql:host='.$db['host'].';dbname='.$db['database'], $db['user'], $db['pass']);
		$Connect->query("set names 'utf8'");

	include_once "51api.php";
	try {
		$OpenApp_51->check_user();
	} catch (Exception $e) {
		echo $e->getMessage();
		exit;
	}
		$sql = "select * from `face_resource` where `face_id` = '".$face_id."' limit 1";
		$exec = $Connect->query($sql);
		$result = $exec->fetchAll(PDO::FETCH_ASSOC);
		$user_face = $result[0]['source'];
	//$profile_t = mb_convert_encoding(urldecode($_GET["profile_t"]),"gbk","utf8");
	//$profile_p = urldecode($_GET["profile_p"]);
	try {
		$ret = $OpenApp_51->api_client->call_method("profile.set51ML", array("profile"=>'
						<p><a href="http://apps.51.com/face"><img src="'.$user_face.'" id="homeshowimg" /></a></p>'));
		if($ret['result'] == 1) {
			echo $callback."(1)";	//success
		} else {
			echo $callback."(2)";	//failed
		}
	} catch (Exception $e) {
		echo $e->getMessage();
		exit;
	}
?>